/*
 *  This file is part of WWWPal.
 *
 *  Copyright (C) 2003  Dr. John Punin, Department of Computer Science
 *  Rensselaer Polytechnic Institute
 *
 *  WWWPal is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  WWWPal is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#ifndef WLOGR_MAIN_H
#define WLOGR_MAIN_H

#include <sys/fcntl.h>
#include <math.h>
#include <assert.h>
#include <sys/stat.h>
#include <LOGR_webstat.h>
#include <LOGR_xml_parse_conf.h>

#include "WLOGR_frame.h"

#define FLINE 120
#define WIDTH 1000    /* arbitrary width and height values */
#define HEIGHT 1000

#define DEFAULT_GRAPH_FILE "default.gr"
#define DEFAULT_EXTENDED_LOG_FILE "extended_log"
#define DEFAULT_LOGML_FILE "default.lml"
#define DEFAULT_XML_CONF_FILE "webloggr.conf.xml"

#define DEFAULT_LOG_ROOT_DIRECTORY "/usr/local/www/logs/www.cs.rpi.edu"
#define DEFAULT_WEB_SERVER "http://www.cs.rpi.edu/"
#define DEFAULT_LOCAL_DOMAIN ".cs.rpi.edu"
#define DEFAULT_NUMBER_ELEMENTS 200
#define DEFAULT_NUMBER_KEYWORDS 50
#define DEFAULT_RESOLVE_TIMEOUT 5
#define DEFAULT_SUBNET_ADDRESS1 "128.113.96.0/24"
#define DEFAULT_SUBNET_ADDRESS2 "128.213.0.0/16"

#define DEFAULT_NUMBER_GRAPHS 100
#define DEFAULT_NUMBER_USERS 100
#define DEFAULT_MINIMUM_EDGES 2
#define DEFAULT_MAXIMUM_EDGES 100


#define WEBLOGGR_HELP_INFO "\nUsage: webloggr [-conf [conffile]] [-gf [graphfile]] [-(l|logf) [logfile]] [-(o|lmlf) [logmlfile]] [-logroot directory] [-webserver uri] [-domain dns] [-subnet cidr] [-prefix uriprefix] [-n [num]] [-x] [-c] [-rhip] [-rhip_timeout [secs]] [-cus] [-report_prefix name] [-num_graphs [num] [-min_edges [num]] [-num_users [num]] [-max_edges [num]] [-(h|?)] [-version] [logfile]\n \
\
-conf [conffile]\t to read the configuration file - default is webloggr.conf.xml\n \
-gf [graphfile]\t\t to read xgmml graph file - default is default.gr\n \
-(l|logf) [logfile]\t to read log file - default is extended_log\n \
-(o|lmlf) [logmlfile]\t to write logml file - default is default.lml\n \
-logroot directory\t the root directory of the log files\n \
-webserver uri\t\t the uri of the web server of the log files \n\t\t\te.g http://www.cs.rpi.edu/\n \
-domain dns\t\t the domain of the web server of the log files \n\t\t\te.g .cs.rpi.edu \n \
-subnet cidr\t\t the CIDR of the subnet of the web server of the log files \n\t\t\te.g 128.213.0.0/16. Several subnet addresses can be set \n\t\t\trepeating this parameter\n \
-prefix [uriprefix]\t the uri prefix of all uris to be read in the log file \n\t\t\te.g http://www.cs.rpi.edu/~puninj/\n \
-n [num]\t\t the number of elements (pages, referers, hosts, etc ) \n\t\t\tto be reported - default is 200\n \
-nk [num]\t\t the number of keywords to be reported - default is 50\n \
-x\t\t\t the format of the log file is extended logs \n\t\t\t- default is extended\n \
-c\t\t\t the format of the log file is common logs \n\t\t\t- default is extended\n \
-rhip\t\t\t to resolve host name from IP\n \
-rhip_timeout [secs]\t to set timeout seconds to resolve host names from IP \n\t\t\t - default is 5 secs\n \
-cus\t\t\t to compute user sessions\n \
-report_prefix name\t to generate html log reports. The name is used as the \n\t\t\tprefix for the reports.\n \
-num_graphs [num]\t the number of graphs of user sessions to be reported - default is 100\n \
-min_edges [num]\t the minimum number of edges in the graphs of the user sessions - default is 2\n \
-num_users [num]\t the number of users of user sessions to be reported - default is 100\n \
-max_edges [num]\t the maximum number of edges of the graphs of the user sessions - default is 100\n \
-(h|?)\t\t\t to display this message\n \
-version\t\t to display version of webloggr\n"

#define WEBLOGGR_VERSION_INFO "webloggr v1.0"

#define MAX_CIDR 10

typedef struct _main_frame{
  LNode_type *ltgr_frame;
  LNode_type *cur_node_tgf;
  int cur;
  int findex;
  char *basename;
  PNODE nroot; /* next root vertex */
  WebStatPtr wsn;

  ConfigNodePtr cnp;

/* COMMAND LINE ARGUMENTS */
  char *conf_file;
  char *graph_file;
  char *log_file;
  char *log_prefix;
  char *logml_file;
  char *log_root_dir;
  char *web_server_name;
  char *local_domain;
  char *uri_prefix;
  char *report_prefix;
  char *report_dir;
  int log_type;
  int num_elements;
  int num_keywords;
  int nof;
  int rhip;
  int rhip_timeout;
  int ncidr;
  char *array_cidr[MAX_CIDR];
/* USER SESSIONS */    
  int compute_users;
  int num_graphs;
  int min_edges;
  int num_users;
  int max_edges;
} mainFrame;

void
delete_main_frame(mainFrame *mf);
mainFrame *
new_main_frame(void);
int
read_command_line(mainFrame *mf, int argc, char *argv[]);
void
init_graph(GraphFrame *gf);
int 
read_regular_file(char *filename, char **stext);
char *
get_base_name(char *filename);
void
set_shape_from_attributes(GraphFrame *gf);

#endif

